﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="codegen"
    targetNamespace="urn:effun-net-dycox-vstools-codegen"
    elementFormDefault="qualified"
    xmlns="urn:effun-net-dycox-vstools-codegen"
    xmlns:mstns="urn:effun-net-dycox-vstools-codegen"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

  <xs:element name="options">
    <xs:complexType>
      <xs:all>
        <xs:element name="baseTypes" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="type" minOccurs="0" maxOccurs="unbounded" type="xs:token"></xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="mapping" minOccurs="0" type="mstns:typeMapping"></xs:element>
        <xs:element name="customAttributes" type="customAttributes" minOccurs="0"></xs:element>
      </xs:all>
      <xs:attribute name="access" type="mstns:memberAccess" default="Public" ></xs:attribute>
      <xs:attribute name="isPartial" type="xs:boolean" default="true"></xs:attribute>
      <xs:attribute name="modifier" type="typeInheritanceModifier"></xs:attribute>
      <xs:attribute name="changeTracking" type="changeTracking" default="Both"></xs:attribute>
      <xs:attribute name="dycoxChangeTracking" type="xs:boolean"></xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="memberAccess">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Public"></xs:enumeration>
      <xs:enumeration value="Family"></xs:enumeration>
      <xs:enumeration value="Assembly"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="memberInheritanceModifier">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Virutal"></xs:enumeration>
      <xs:enumeration value="Abstract"></xs:enumeration>
      <xs:enumeration value="Override"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="changeTracking">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Auto"></xs:enumeration>
      <xs:enumeration value="Changing"></xs:enumeration>
      <xs:enumeration value="Changed"></xs:enumeration>
      <xs:enumeration value="Both"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="typeInheritanceModifier">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Abstract"></xs:enumeration>
      <xs:enumeration value="Final"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="identifierCase">
    <xs:restriction base="xs:string">
      <xs:enumeration value="NoChange"></xs:enumeration>
      <xs:enumeration value="Pascal"></xs:enumeration>
      <xs:enumeration value="Camel"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="clrPrimitiveTypes">
    <xs:restriction base="xs:string">
      <xs:enumeration value="string"></xs:enumeration>
      <xs:enumeration value="int"></xs:enumeration>
      <xs:enumeration value="bool"></xs:enumeration>
      <xs:enumeration value="long"></xs:enumeration>
      <xs:enumeration value="short"></xs:enumeration>
      <xs:enumeration value="byte"></xs:enumeration>
      <xs:enumeration value="double"></xs:enumeration>
      <xs:enumeration value="float"></xs:enumeration>
      <xs:enumeration value="decimal"></xs:enumeration>
      <xs:enumeration value="uint"></xs:enumeration>
      <xs:enumeration value="ushort"></xs:enumeration>
      <xs:enumeration value="ulong"></xs:enumeration>
      <xs:enumeration value="sbyte"></xs:enumeration>
      <xs:enumeration value="char"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="clrCommonTypes">
    <xs:restriction base="xs:string">
      <xs:enumeration value="DateTime"></xs:enumeration>
      <xs:enumeration value="Guid"></xs:enumeration>
      <xs:enumeration value="TimeSpan"></xs:enumeration>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="clrDataTypes">
    <xs:union memberTypes="clrPrimitiveTypes clrCommonTypes xs:token"></xs:union>
  </xs:simpleType>

  <xs:attribute name="readOnly" type="xs:boolean"></xs:attribute>
  <xs:attribute name="propertyType" type="clrDataTypes"></xs:attribute>
  <xs:attribute name="modifier" type="memberInheritanceModifier"></xs:attribute>
  <xs:attribute name="access" type="memberAccess"></xs:attribute>
  <xs:attribute name="setterAccess" type="memberAccess">
    <xs:annotation>
      <xs:documentation>Not supported yet!</xs:documentation>
    </xs:annotation>
  </xs:attribute>
  <xs:attribute name="ignore" type="xs:boolean" default="false"></xs:attribute>
  <xs:attribute name="doc" type="xs:string"></xs:attribute>

  <xs:complexType name="propertySerialization">
    <xs:attribute name="disabled" type="xs:boolean"></xs:attribute>
    <xs:attribute name="name" type="xs:string"></xs:attribute>
    <xs:attribute name="member">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Property"></xs:enumeration>
          <xs:enumeration value="Field"></xs:enumeration>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="constantDeclaration">
    <xs:attribute name="type" >
      <xs:simpleType>
        <xs:union memberTypes="clrDataTypes">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="Type"></xs:enumeration>
            </xs:restriction>
          </xs:simpleType>
        </xs:union>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="value" type="xs:string"></xs:attribute>
  </xs:complexType>

  <xs:complexType name="customAttribute">
    <xs:sequence>
      <xs:element name="param" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:complexContent>
            <xs:extension base="constantDeclaration">
              <xs:attribute name="name" type="xs:token"></xs:attribute>
              <xs:attribute name="casting"  default="implicit">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:enumeration value="implicit"></xs:enumeration>
                    <xs:enumeration value="explicit"></xs:enumeration>
                  </xs:restriction>
                </xs:simpleType>
              </xs:attribute>
            </xs:extension>
          </xs:complexContent>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="type" use="required" type="xs:token"></xs:attribute>
  </xs:complexType>

  <xs:complexType name="customAttributes">
    <xs:sequence>
      <xs:element name="attribute" type="customAttribute" minOccurs="0" maxOccurs="unbounded"></xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="propertyMapping">
    <xs:attribute name="pk" type="xs:boolean"></xs:attribute>
    <xs:attribute name="column" type="xs:Name" ></xs:attribute>
    <xs:attribute name="dbtype" type="xs:string"></xs:attribute>
    <xs:attribute name="nullable" type="xs:boolean"></xs:attribute>
    <xs:attribute name="generated" type="xs:boolean"></xs:attribute>
    <xs:attribute name="timestamp" type="xs:boolean"></xs:attribute>
    <xs:attribute name="auto-sync">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Never"></xs:enumeration>
          <xs:enumeration value="OnInsert"></xs:enumeration>
          <xs:enumeration value="OnUpdate"></xs:enumeration>
          <xs:enumeration value="Always"></xs:enumeration>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="updateCheck">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Never"></xs:enumeration>
          <xs:enumeration value="WhenChanged"></xs:enumeration>
          <xs:enumeration value="Always"></xs:enumeration>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="accessor">
    <xs:attribute name="name" type="xs:Name"></xs:attribute>
    <xs:attribute name="access" type="memberAccess"></xs:attribute>
    <xs:attribute name="modifier" type="memberInheritanceModifier"></xs:attribute>
  </xs:complexType>

  <xs:complexType name="association">
    <xs:all>
      <xs:element name="thisAccessor" minOccurs="0" type="accessor"></xs:element>
      <xs:element name="otherAccessor" minOccurs="0">
        <xs:complexType>
          <xs:complexContent>
            <xs:extension base="accessor">
              <xs:attribute name="pattern">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:enumeration value="default"></xs:enumeration>
                    <xs:enumeration value="IList"></xs:enumeration>
                  </xs:restriction>
                </xs:simpleType>
              </xs:attribute>
            </xs:extension>
          </xs:complexContent>
        </xs:complexType>
      </xs:element>
    </xs:all>
    <xs:attribute name="name" type="xs:Name"></xs:attribute>
    <xs:attribute name="thisProperties" use="required">
      <xs:simpleType>
        <xs:list itemType="xs:Name"></xs:list>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="parentProperties" use="required">
      <xs:simpleType>
        <xs:list itemType="xs:Name">
        </xs:list>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="parentType" type="xs:Name" use="required">
    </xs:attribute>
    <xs:attribute name="deleteRule">
      <xs:simpleType>
        <xs:union memberTypes="xs:Name">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:enumeration value="NO ACTION"></xs:enumeration>
              <xs:enumeration value="CASCADE"></xs:enumeration>
              <xs:enumeration value="SET NULL"></xs:enumeration>
            </xs:restriction> 
          </xs:simpleType>
        </xs:union>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="cardinality">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="OneToMany"></xs:enumeration>
          <xs:enumeration value="OneToOne"></xs:enumeration>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="typeMapping">
    <xs:all>
      <xs:element name="associations" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="foreignKey" type="association" minOccurs="0" maxOccurs="unbounded"></xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:all>
    <xs:attribute name="table" type="xs:Name"></xs:attribute>
    <xs:attribute name="contextProperty" type="xs:string"></xs:attribute>
    <xs:attribute name="ignore" type="xs:boolean"></xs:attribute>
  </xs:complexType>

  <xs:element name="fileOptions">
    <xs:complexType>
      <xs:all>
        <xs:element name="mapping">
          <xs:complexType>
            <xs:attribute name="database" type="xs:string"></xs:attribute>
            <xs:attribute name="contextName" type="xs:string"></xs:attribute>
            <xs:attribute name="contextBaseType" type="xs:string"></xs:attribute>
            <xs:attribute name="provider" >
              <xs:simpleType>
                <xs:restriction base="xs:string">
                  <xs:enumeration value="LinqToSql"></xs:enumeration>
                </xs:restriction>
              </xs:simpleType>
            </xs:attribute>
          </xs:complexType>          
        </xs:element>
      </xs:all>
      <xs:attribute name="changeTracking" type="changeTracking"></xs:attribute>
    </xs:complexType>
  </xs:element>

  <xs:element name="defaultValue" type="constantDeclaration"></xs:element>
  <xs:element name="customAttributes" type="customAttributes"></xs:element>
  <xs:element name="mapping" type="propertyMapping"></xs:element>
  
</xs:schema>
